CPPFLAGS  = -g -ggdb -Wall -I./inc -include./inc/shared/Utils.h
LDFLAGS   = 
LIBS      = -lpthread -lncurses
CC        = g++

OUT_TEST      = test
OUT_SIMAPP    = simapp
OUT_SIMULATOR = libsimulator.a

TEST          = bin/$(OUT_TEST)
SIMAPP        = bin/$(OUT_SIMAPP)
SIMULATOR     = lib/$(OUT_SIMULATOR)

SRC_NODE      = $(wildcard ./src/node/*.cpp)
SRC_PROTOCOL  = $(wildcard ./src/protocol/*.cpp)
SRC_SERIAL    = $(wildcard ./src/serial/*.cpp)
SRC_SHARED    = $(wildcard ./src/shared/*.cpp)
SRC_SIMULATOR = $(wildcard ./src/simulator/*.cpp)
SRC_TESTAPP   = $(wildcard ./src/testapp/*.cpp)
SRC_SIMAPP    = $(wildcard ./src/simapp/*.cpp)

OBJ_NODE      = $(patsubst %.cpp,%.o,$(SRC_NODE))
OBJ_PROTOCOL  = $(patsubst %.cpp,%.o,$(SRC_PROTOCOL))
OBJ_SERIAL    = $(patsubst %.cpp,%.o,$(SRC_SERIAL))
OBJ_SHARED    = $(patsubst %.cpp,%.o,$(SRC_SHARED))
OBJ_SIMULATOR = $(patsubst %.cpp,%.o,$(SRC_SIMULATOR))
OBJ_TESTAPP   = $(patsubst %.cpp,%.o,$(SRC_TESTAPP))
OBJ_SIMAPP    = $(patsubst %.cpp,%.o,$(SRC_SIMAPP))

# General files
SRCS	= $(SRC_NODE) $(SRC_PROTOCOL) $(SRC_SERIAL) $(SRC_SHARED) $(SRC_SIMULATOR)
OBJS	= $(OBJ_NODE) $(OBJ_PROTOCOL) $(OBJ_SERIAL) $(OBJ_SHARED) $(OBJ_SIMULATOR)
DEPS	= $(patsubst %.o,%.d,$(OBJS))

# Eyenode test application files
SRCS_TEST = $(SRC_TESTAPP)
OBJS_TEST = $(OBJ_TESTAPP)
DEPS_TEST = $(patsubst %.o,%.d,$(OBJS_TEST))

# Simulator test application files
SRCS_SIMAPP = $(SRC_SIMAPP)
OBJS_SIMAPP = $(OBJ_SIMAPP)
DEPS_SIMAPP = $(patsubst %.o,%.d,$(OBJS_SIMAPP))

all: simulator simapp

# Eyenode test application
eyenode: $(OBJS) $(OBJS_TEST)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o $(TEST) $(OBJS) $(OBJS_TEST) $(LIBS)

# Simulator library
simulator: $(OBJS)
#	$(CC) $(CPPFLAGS) $(LDFLAGS) -fPIC -shared -Wl,-soname,$(OUT_SIMULATOR).1 -o $(SIMULATOR) $(OBJS) $(OBJS_W) $(LIBS)
	$(AR) rcs $(SIMULATOR) $(OBJS)

# Simulator test application
simapp: $(OBJS) $(OBJS_SIMAPP)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o $(SIMAPP) $(OBJS) $(OBJS_SIMAPP) $(LIBS)

clean:
	@find . -name "*.o" | xargs rm
#	@find . -name "*.d" | xargs rm

# Dependencies
deps: $(SRCS)
	$(CC) $(CPPFLAGS) -MD -E $(SRCS) > /dev/null

#-include $(DEPS)
